#ifndef PP_LOADODE_H
#define PP_LOADODE_H

#include <stdio.h>
#include <stdlib.h>
#include "data.h"
#include "macros.h"

t1B* PP_LoadCode(t1B* pointer)
{
    t1B* pTemp = pointer;

    uint32 file_version;
    READFILE(file_version,uint32,pTemp);
    //Ctrl
    uint32 i;
    for(i = 0; i < 11; i++)
    {
        READFILE(tavm_tables[i].start,addr_t,pTemp);
        READFILE(tavm_tables[i].size,addr_t,pTemp);
        tavm_tables[i].start += (uint32)tavm_file_data;
    }

    READFILE(tavm_active_agents_count,aid_t,pTemp);
    READFILE(tavm_passive_agents_count,aid_t,pTemp);

    READFILE(tavm_ports_count,port_t,pTemp);

    READFILE(tavm_datamap_count,addr_t,pTemp);


    //Agents Static
    tavm_agents_s = (Agent_Static*)tavm_tables[TID_AGENTS_S].start;
    pTemp += tavm_tables[TID_AGENTS_S].size;

    //Code
    pTemp += tavm_tables[TID_CODE].size;

    //Ports Static
    tavm_ports_s = (Port_Static*)tavm_tables[TID_PORTS_S].start;
    pTemp += tavm_tables[TID_PORTS_S].size;

    //Data Map

    tavm_datamap = (DataEntry*)tavm_tables[TID_DATA_MAP].start;
    pTemp += tavm_tables[TID_DATA_MAP].size;
    //Data
    pTemp += tavm_tables[TID_DATA_S].size;

    //Var

    //Agents Var
    tavm_agents_v = (Agent_Var*)tavm_tables[TID_AGENTS_V].start;
    pTemp += tavm_tables[TID_AGENTS_V].size;

    //Ports Var
    tavm_ports_v = (Port_Var*)tavm_tables[TID_PORTS_V].start;
    pTemp += tavm_tables[TID_PORTS_V].size;

    //Data
    pTemp += tavm_tables[TID_PORTS_V].size;


    return pTemp;
}

#endif

